using System.Collections;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ServerControls.Repeater
{
    public class Repeater : System.Web.UI.WebControls.Repeater
    {
        private ITemplate emptyTemplate;

        public ITemplate EmptyTemplate
        {
            get { return emptyTemplate; }
            set { emptyTemplate = value; }
        }

        protected override void CreateControlHierarchy(bool useDataSource)
        {
            IEnumerable data = GetData();
            if (EmptyTemplate != null && data != null && !data.GetEnumerator().MoveNext())
            {
                WebControl control = new WebControl(HtmlTextWriterTag.Div);
                EmptyTemplate.InstantiateIn(control);
                Controls.Add(control);
            }
            else
            {
                base.CreateControlHierarchy(useDataSource);
            }
        }
    }
}